//累计下单人数弹窗
import React from 'react'
import { Modal } from "antd";
import TheTable from '@/components/TheTable'
import ThePagination from '@/components/ThePagination'
import TheQueryForm from '@/components/TheQueryForm';
import { getDateTime3 } from '@/utils/getDate'
import _ from 'lodash'
import { apiSharerBuyOrderPage } from '@/request/distribution/sharerManagement.js'

export default class OrderNumModal extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      isModal: false, //弹窗是否打开
      sharedById: null,//详情id
      columns: [
        {
          title: "会员昵称",
          dataIndex: "nickName",
          key: "nickName",
        },
        {
          title: "会员ID",
          dataIndex: "memberId",
          key: "memberId",
        },
        {
          title: "累计下单数",
          dataIndex: "orderCount",
          key: "orderCount",
        },
        {
          title: "累积退单数",
          dataIndex: "refundCount",
          key: "refundCount",
        }
      ],
      dataSource: [],
      pageData: {
        pageNo: 1,
        pageSize: 10
      },
      total: 0,
      queryForm: {}
    }
  }
  openModal = (id, queryForm) => {
    console.log(queryForm);
    if (queryForm.hasOwnProperty('startTime') && queryForm.hasOwnProperty('endTime')) {
      this.setState({
        queryForm: { startTime: queryForm.startTime, endTime: queryForm.endTime },
      })
    } else {
      this.setState({
        queryForm: {},
      })
    }
    this.setState({ isModal: true, sharedById:id }, () => {
      this.getData()
    })
  }
  getData = async () => {
    const { sharedById, pageData, queryForm} = this.state
    console.log(queryForm);
    await apiSharerBuyOrderPage({ sharedById, param: { ...pageData }, ...queryForm }).then(res => {
      if (res.code === 0) {
        this.setState({
          dataSource: res.data,
          total: res.totalCount
        })
      }
    })
  }
  //分页
  pageChange = (pageNo, pageSize) => {
    this.setState({
      pageData: {
        pageNo, pageSize
      }
    }, () => {
      this.getData()
    })
  }
  render() {
    let { isModal, columns, pageData: { pageNo, pageSize }, total, dataSource, searchOption } = this.state
    return (
      <Modal title="下单用户" width={'70%'} visible={isModal} footer={null} destroyOnClose onCancel={() => { this.setState({ isModal: false }) }}>
        <TheTable columns={columns} dataSource={dataSource} rowKey={record => record.shareById} />
        <ThePagination
          pageNo={pageNo}
          pageSize={pageSize}
          total={total}
          pageChange={this.pageChange}
        />
      </Modal >
    )
  }
}
